refactor(audience): SDK test pinning and sample-app custom events (SDK-277)#727
Open
ImmutableJeffrey wants to merge 10 commits intochore/sdk-272-pr-2-catalogues-and-test-infrafrom
Conversation
1d1a56d to
9c7496b
Compare
7ccd158 to
9c4da2e
Compare
9c7496b to
91f1783
Compare
9c4da2e to
ba0bcf4
Compare
ConstantsTests already pinned Constants.LibraryVersion against the
package.json "version" field so the two cannot silently drift; the
matching pin for Constants.LibraryName ("com.immutable.audience") and
package.json "name" was missing. Both feed context.library /
context.libraryVersion on every outgoing event, so a rename of either
side without the other would silently miscategorise events on the
backend.
Add a sibling LibraryName_MatchesPackageJson test that walks up to
the same package.json and asserts the two strings match. Reuses the
existing ReadPackageJson helper.
Follow-up to SDK-272 (centralisation of duplicated literals).
…off*Ms
HttpTransportTests pinned the backoff schedule with literal millisecond
numbers (5_000 / 10_000 / 20_000 / 40_000 / 60_000). Constants.HttpBackoff*Ms
now own those values, but the tests still hardcoded the numbers, so a
change to the constants would have flipped production behaviour while
the tests kept passing against the old expectations.
Switch every BackoffMs / NextAttemptAt assertion to derive from
Constants.HttpBackoff{1st,2nd,3rd,4th,Cap}Ms.
Follow-up to SDK-272 (centralisation of duplicated literals).
ParseLowercaseString was added in the SDK-272 stack as the inverse of
ToLowercaseString and consumed by the sample app to map wire strings
back to the enum. It had no direct test, so a typo in any of the eight
case branches or in the Custom fallback would land silently.
Add three parametrised cases:
- Each known enum value maps from its lowercase wire form.
- Mixed-case ("Steam", "STEAM", "Passport") still resolves
via ToLowerInvariant, matching the documented behaviour.
- null, empty, and unknown values fall back to Custom (the parser
never throws so producer code always gets a usable enum).
Follow-up to SDK-272 (centralisation of duplicated literals).
…l platforms Init's lowercase-normalisation tests covered "Steam" / "STEAM" / "steam" but not the other four public DistributionPlatforms values (Epic, GOG, Itch, Standalone). Adding a sixth platform would land without coverage. Add a parametrised Init_LowercasesDistributionPlatform_AcrossAllPublicValues test that takes each public DistributionPlatforms constant, uppercases it, runs Init, and asserts the canonical lowercase form is restored. Follow-up to SDK-272 (centralisation of duplicated literals).
…sages The two centralised message catalogues had no direct unit tests. Behavioural tests observed wording loosely via Does.Contain assertions, which let typos and partial rewords through. Add MessagesTests.cs with one fixture per catalogue. Each constant / formatter has an exact-string assertion. A reword anywhere in the catalogue now fails the build. Follow-up to SDK-272 (centralisation of duplicated literals).
91f1783 to
427f963
Compare
cf5c443 to
ea260bf
Compare
…ent drafts Two Unity-only test fixtures the dotnet test runner cannot reach (DeviceCollector depends on UnityEngine.SystemInfo / Application; SampleAppUxml needs Unity test framework gating). Both run under the Unity Test Framework once the project is opened in the editor. DeviceCollectorTests (src/Packages/Audience/Tests/Editor/, excluded from the headless dotnet build by Audience.Tests.csproj's Compile Remove="Editor/**/*.cs" rule) pin DeviceCollector's emitted key sets against GameLaunchPropertyKeys and ContextKeys, assert that no unknown keys leak in either direction, and verify every string-typed value is capped at Constants.MaxFieldLength. SampleAppUxmlAlignmentTests (examples/audience/Assets/SampleApp/Tests/ Runtime/, gated by the existing UNITY_INCLUDE_TESTS define on the SampleApp.Tests asmdef) reads Resources/AudienceSample.uxml as XML and asserts every SampleAppUi name and Css constant that is slug-shaped (lowercase / dashes / no spaces) appears as a name= or class= attribute somewhere in the markup. Runtime-only CSS toggles (state-warn, copied, narrow, has-value, etc.) are filtered by the slug-shape heuristic so the test only flags constants that look like they should map directly to UXML. Both files compile cleanly. They will not run under dotnet test. Run them via Unity Test Runner. Follow-up to SDK-272 (centralisation of duplicated literals).
Per the user's "everything random goes in a constant" stance, this is applied against the previous session's recommendation that scenario descriptors read better inline. Recording the override on the user's explicit request. Follow-up to SDK-272 (centralisation of duplicated literals).
…leAppCustomEvents The sample-app demo catalogue (sign_up, sign_in, email_acquired, wishlist_add, wishlist_remove, game_page_viewed, link_clicked, screen_viewed) had its event-name strings inline at every call site. A rename touches the catalogue, the screen_viewed Track call, and each Unity live-fire test that drives the catalogue UI. Move the eight names into a new internal SampleAppCustomEvents class under the sample-app Scripts assembly. Update AudienceSample.Events.cs, AudienceSample.cs (screen_viewed Track), and SampleAppLiveFireTests.cs (button and field lookups by event name) to reference the constants. Per the user's "everything random goes in a constant" stance, applied against the previous session's recommendation that the demo content read better inline. Recording the override on the user's explicit request. Follow-up to SDK-272 (centralisation of duplicated literals).
…mpleAppCustomEventPropertyKeys The sample-app demo catalogue, screen_viewed Track call, and the typed-event live-fire tests had property keys (method, source, gameId, platform, gameName, slug, url, label, path) inline at every call site. Each key duplicates between the catalogue's EventField definition and the live-fire test's UI lookup. Add SampleAppCustomEventPropertyKeys alongside SampleAppCustomEvents (mirrors the SDK's EventPropertyKeys naming) and reference the constants from AudienceSample.Events.cs, AudienceSample.cs (the screen_viewed props dictionary), and SampleAppLiveFireTests.cs (the TypedEventField field-name lookups). Includes gameName and slug beyond the user's listed seven keys: same inline-property-key category, same migration treatment. Per the user's "everything random goes in a constant" stance, applied against the previous session's recommendation that the demo content read better inline. Recording the override on the user's explicit request. Follow-up to SDK-272 (centralisation of duplicated literals).
…d lookups in live-fire tests
SampleAppLiveFireTests filled the Resource, Purchase, and
MilestoneReached typed-event forms by looking up TextFields with
inline property-name strings ("currency", "amount", "value", "name").
The SDK already centralises these as EventPropertyKeys.Currency /
.Amount / .Value / .Name, made visible to the sample-app tests
through the existing InternalsVisibleTo grant.
Reference EventPropertyKeys.X from the five lookup sites instead of
re-typing the wire-format strings.
Discovered during the sample-app demo property-key centralisation
pass; kept separate because these keys belong to the SDK's typed-event
surface, not the sample-app demo catalogue.
Per the user's "everything random goes in a constant" stance.
Follow-up to SDK-272 (centralisation of duplicated literals).
ea260bf to
4bacd74
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Constants.LibraryNameagainst thenamefield inpackage.json.Constants.HttpBackoff*Msinstead of magic numbers.IdentityTypeExtensions.ParseLowercaseStringcases (known platform, unknown, null, empty, mixed case fallback toCustom).DistributionPlatformcasing tests across all platform values.AudienceErrorMessagesandAudienceArgumentMessagesconstants and formatters to their exact wording so a reword fails the build.DeviceCollectorTestsandSampleAppUxmlAlignmentTestsdrafts; both gated byUNITY_INCLUDE_TESTSand excluded from the headlessdotnetbuild viaAudience.Tests.csproj.TestEventNamesfor per-test event-name strings.SampleAppCustomEventsandSampleAppCustomEventPropertyKeysfor the sample-app demo catalogue's custom event names and property keys.SampleAppLiveFireTeststhroughEventPropertyKeys.OnErrorcallback contract unchanged.Linear: SDK-277